﻿package mortal.game.view.platform
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.platform.platformThunder.*;

    public class PlatformVIPGiftsModule extends BaseWindow
    {
        private var _bg:GImageBitmap;
        private var _giftBagList:GTileList;
        private var _upgradeBtn:GLoadingButton;
        private var _vipLinkTxt:GButton;
        private var _vipLevelTxt:GTextFiled;
        private var _selectedGiftIndex:int;
        private var _panel:GSprite;
        public static var platformData:PlatformVIPGiftShowData;

        public function PlatformVIPGiftsModule()
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._bg)
            {
                this._bg.dispose(param1);
                this._bg = null;
            }
            if (this._upgradeBtn)
            {
                this._upgradeBtn.dispose(param1);
                this._upgradeBtn = null;
            }
            if (this._giftBagList)
            {
                this._giftBagList.dispose(param1);
                this._giftBagList = null;
            }
            if (this._vipLinkTxt)
            {
                this._vipLinkTxt.dispose(param1);
                this._vipLinkTxt = null;
            }
            if (this._vipLevelTxt)
            {
                this._vipLevelTxt.dispose(param1);
                this._vipLevelTxt = null;
            }
            if (this._panel)
            {
                this._panel.dispose(param1);
                this._panel = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        protected function onClickHandle(event:MouseEvent) : void
        {
            if (event.target == this._upgradeBtn)
            {
                GameUtil.gotoPlatformVipUpgrade();
            }
            else if (event.target == this._vipLinkTxt)
            {
                GameUtil.gotoPlatformVipHelp();
            }
            return;
        }// end function

        private function getGroupByTPlatformGift(param1:TPlatformGift) : PlatformVIPGiftGroup
        {
            var _loc_2:* = new PlatformVIPGiftGroup();
            _loc_2.platformGift = param1;
            _loc_2.receiveType = PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(param1);
            return _loc_2;
        }// end function

        private function getGiftDataProvider() : DataProvider
        {
            var _loc_4:PlatformVIPGiftGroup = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = PlatformGiftConfig.instance.vipGiftVec;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = this.getGroupByTPlatformGift(_loc_2[_loc_3]);
                if (this._selectedGiftIndex <= 0)
                {
                    if (_loc_4.receiveType == PlatformVIPGiftGroup.CanReceive)
                    {
                        this._selectedGiftIndex = _loc_3;
                    }
                }
                _loc_1.addItem(_loc_4);
                _loc_3++;
            }
            return _loc_1;
        }// end function

        public function refresh() : void
        {
            this._selectedGiftIndex = -1;
            if (this._giftBagList)
            {
                this._giftBagList.dataProvider = this.getGiftDataProvider();
                this._giftBagList.drawNow();
                this._giftBagList.scrollToIndex(this._selectedGiftIndex);
            }
            if (this._panel)
            {
                if (this._panel is PlatformThunderVipPanel)
                {
                    (this._panel as PlatformThunderVipPanel).refresh();
                }
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:SProxyInfo = null;
            super.createDisposedChildrenImpl();
            if (platformData)
            {
                if (platformData.specialClass)
                {
                    this._panel = UICompomentPool.getUICompoment(platformData.specialClass as Class);
                    this._panel.x = platformData.specialPanelPos.x;
                    this._panel.y = platformData.specialPanelPos.y;
                    this.addChild(this._panel);
                    setSize(platformData.size.x, platformData.size.y);
                    title = platformData.title;
                }
                else
                {
                    this._selectedGiftIndex = -1;
                    setSize(platformData.size.x, platformData.size.y);
                    title = platformData.title;
                    this._bg = UIFactory.gImageBitmap(platformData.bgResName, platformData.bgPos.x, platformData.bgPos.y, this);
                    this._upgradeBtn = UIFactory.gLoadingButton(platformData.vipUpgradeBtnName, platformData.vipUpgradePos.x, platformData.vipUpgradePos.y, platformData.vipUpgradeSize.x, platformData.vipUpgradeSize.y, this);
                    this._upgradeBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
                    this._giftBagList = UIFactory.tileList(platformData.giftListPos.x, platformData.giftListPos.y, 690, 332, this);
                    this._giftBagList.columnWidth = platformData.cellSize.x;
                    this._giftBagList.rowHeight = platformData.cellSize.y;
                    this._giftBagList.setStyle("cellRenderer", platformData.cellRender);
                    this._giftBagList.direction = GBoxDirection.VERTICAL;
                    this._giftBagList.dataProvider = this.getGiftDataProvider();
                    this._giftBagList.drawNow();
                    this._vipLevelTxt = UIFactory.gTextField("0级会员", platformData.vipLevelTxtPos.x, platformData.vipLevelTxtPos.y, 220, 40, this, GlobalStyle.textFormatLv.setSize(14));
                    this._vipLevelTxt.mouseEnabled = false;
                    _loc_1 = Cache.instance.platform.proxyVipInfo;
                    if (_loc_1)
                    {
                        this._vipLevelTxt.text = String(_loc_1.proxyLv) + "级会员";
                    }
                    if (ParamsConst.instance.platformVipHelpUrl != "")
                    {
                        this._vipLinkTxt = UIFactory.gButton("了解更多vip规则", platformData.vipLinktxtPos.x, platformData.vipLinktxtPos.y, 130, 28, this, "GreenLinkButtonSize14");
                        this._vipLinkTxt.configEventListener(MouseEvent.CLICK, this.onClickHandle);
                    }
                }
            }
            return;
        }// end function

    }
}
